component{
	include "../../inc/lib.cfm"; 
	
	public any function list(rc){
		var result = {};
		var offset = (rc.page-1)*rc.rows;
		hql = "from articlecomment where " & rc.sqlWhere & rc.sqlSort;
		var result["rows"] = ormExecuteQuery(hql, false, {maxResults=rc.rows, offset=offset});
		var totalhql = "select count(id) as total from articlecomment where " & rc.sqlWhere ;
		var result["total"] = ormExecuteQuery(totalhql, true);
		
		for(i = 1; i <= arraylen(result.rows); i++)
		{
			result.rows[i]['state'] = result.rows[i].hasChildren() ? 'closed' : 'open';
		}
		return result;
	}
	
	//发布评论
	public any function publish(numeric id){
		q = entityLoadByPk("articlecomment", LSParseNumber(arguments.id));
		if( q.getispublish()){v = 0;}else{v = 1;}
		q.setispublish(v);
		entitySave(q);
		transactionCommit();
		return v;
	}
	
	//删除评论
	public any function delete(numeric id){
		var q = entityLoadByPk("articlecomment", arguments.id);
		entityDelete(q);
		transactionCommit();
		return q;
	}
	
	public any function save(any rc){
		transaction {
            var q = entityNew("articlecomment");
            if(LSParseNumber(rc.articlebaseid) >0){
				var e = entityLoadByPk("articlebase", LSParseNumber(rc.articlebaseid));
				e.addArticlecomment(q);
			}
			
			if(rc.articlecommentid!=0){
				var c = entityLoadByPk("articlecomment", LSParseNumber(rc.articlecommentid));
				c.addChildren(q);
			}
			
			include "../../inc/saveandupdate.cfm";		
        }
        return q;
	}
	
	public any function update(any rc){
		transaction {
            var q = entityLoadByPk("articlecomment", rc.id);
			include "../../inc/saveandupdate.cfm";
        }
        return q;
	}
	
	public any function get(numeric id){
		result = entityLoadByPk("articlecomment", arguments.id);
		return result;
	}
	
}